#!/usr/bin/env python
import LCD1602
import time

def setup():
    LCD1602.init(0x27, 1)   # init(slave address, background light)
    LCD1602.write(0, 0, 'Greetings!!')
    LCD1602.write(1, 1, 'Welcome here!')
    time.sleep(2)

def loop():
    space = '                '
    greetings = 'Thank you for buying Raspberry! ^_^'
    greetings = space + greetings
    while True:
        tmp = greetings
        for i in range(0, len(greetings)):
            LCD1602.write(0, 0, tmp)    #当要显示的字符串过长时，会自动在LCD的第二行显示
            tmp = tmp[1:]   #每次循环去掉字符串首位字符，实现字幕向左移动的效果
            time.sleep(0.8)
            LCD1602.clear()

def destroy():
    pass    

if __name__ == "__main__":
    try:
        setup()
        while True:
            loop()
    except KeyboardInterrupt:
        destroy()
